package site.kitcheng.springboottest.infra.utils;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;

/**
 * ClassName: Test
 * Package: site.kitcheng.springboottest.infra.utils
 * Description:
 *
 * @Author jiangCheng
 * @Create 2025/2/24 11:29
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) throws Exception {
        KeyPair keyPair = KeyPairGeneratorUtil.generateKeyPair();
        PublicKey aPublic = keyPair.getPublic();
        PrivateKey aPrivate = keyPair.getPrivate();
        String privateKey =  Base64.getEncoder().encodeToString(aPrivate.getEncoded());
        String publicKey =  Base64.getEncoder().encodeToString(aPublic.getEncoded());
        String property = System.getProperty("user.dir");
        String path = property + File.separator + "src"+ File.separator + "main"+File.separator+"resources"+File.separator+"encrypt"+File.separator+"publicKey.pem";
        FileUtils.writeStringToFile(new File(path), publicKey, Charset.defaultCharset());
        String  privateKeyPath = property + File.separator + "src"+ File.separator + "main"+File.separator+"resources"+File.separator+"encrypt"+File.separator+"privateKey.pem";
        FileUtils.writeStringToFile(new File(privateKeyPath), privateKey, Charset.defaultCharset());
    }
}
